﻿using System.Collections;
using static System.Console;

namespace BaseSyntax.Collection.EnumrableTest
{
	public static class MethodDefine
	{
		// 使用属性的方式
		public static IEnumerable Ages
		{
			get
			{
				for (int i = 0; i < 10; i++)
				{
					yield return i;
				}
			}
		}
		// 方法定义返回类型为 IEnumerable
		public static IEnumerable SimpleList()
		{
			for (int i = 0; i < 10; i++)
			{
				if (i == 4)
				{
					yield break;
				}
				yield return i;
			}
			// yield return "string 1";
			// yield return "string 2";
			// yield return "string 3";
		}

		public static void test()
		{
			foreach (int item in SimpleList())
			{
				WriteLine("aa");
				WriteLine(item);
			}

			foreach (int i in Ages)
			{
				WriteLine("bb");
				WriteLine(i);
			}
			
			ReadKey();
		}
	}
}